<?php
// +----------------------------
// | Created by PhpStorm
// +----------------------------
// | Author: YnnSon
// +----------------------------
namespace app\api\controller\v1;

use app\api\model\Message as MessageModel;
use app\api\validate\ParameterMustBePositiveInteger;
use app\lib\exception\SuccessMessage;
use think\Request;

/**
 * 消息
 * Class Message
 * @package app\api\controller\v1
 */
class Message extends BaseController
{
    /**
     * @desc 检查用户权限
     */
    protected $beforeActionList = [
        'checkUserScope' => ['only' => 'getmessagelist'], // 方法名必须全部小写，逗号中间不能有空格！！！
    ];

    /**
     * @Desc 查询消息列表
     * @return array
     */
    public function getMessageList()
    {
        return MessageModel::getMessageList();
    }

    /**
     * @Desc 根据分类ID查询消息列表
     * @param $id
     * @param $page
     * @return array
     */
    public function getMessageDetailList($id,$page)
    {
        return MessageModel::getMessageDetailList($id,$page);
    }

    /**
     * @Desc 更改消息状态
     * @param $id
     *
     * @return SuccessMessage
     */
    public function updateMessageDetail($id)
    {
        (new ParameterMustBePositiveInteger())->scene('id')->goCheck();
        MessageModel::updateMessageDetail($id);
        return new SuccessMessage();
    }

    /**
     * @Desc 获取未读消息个数
     * @return int|string
     */
    public function getMessageNumber()
    {
        return MessageModel::getMessageNumber();
    }

}